<template>
  <div>
    <i-vxe-table ref="iVxeTableRef"  :tableData="tableData"></i-vxe-table>
    <lib-doc :libDocData="libDocData"></lib-doc>
  </div>
</template>

<script lang="ts">
import { defineComponent, reactive, ref } from 'vue'
import { IVxeTable } from 'wd-platform-library'
import {
    TableDataInterFace,
    PageInfoInterFace,
    ResultInterFace
} from 'wd-platform-library/lib/src/IVxeTable/src/IVxeTableInterFace'
import LibDoc from '@/components/LibDoc.vue'
import { LibDocInterface } from '@/service/LibDocService'
interface AppResult {
  appId: string;
  appName: string;
  appSecret: string;
}
export default defineComponent({
    name: 'i_from_demo',
    setup () {
        const iVxeTableRef = ref()
        const dataList = [
            {
                appName: '系统管理',
                appId: 'auth',
                appSecret: 'auth'
            },
            {
                appName: '产品管理',
                appId: 'product',
                appSecret: 'product'
            },
            {
                appName: '营销获客',
                appId: 'channel',
                appSecret: 'channel'
            },
            {
                appName: '线上资源',
                appId: 'consult',
                appSecret: 'consult'
            },
            {
                appName: '订单管理',
                appId: 'order',
                appSecret: 'order'
            },
            {
                appName: '数据统计',
                appId: 'statistics',
                appSecret: 'statistics'
            }
        ]
        const tableData = reactive<TableDataInterFace>({
            type: 'app_table', // 每个表格唯一表示符
            tableInfo: {
                columns: [
                    {
                        field: 'appName',
                        minWidth: 150,
                        title: '应用名称',
                        fixed: 'left',
                        isCheck: false
                    },
                    {
                        field: 'appId',
                        minWidth: 150,
                        title: '应用ID'
                    },
                    {
                        field: 'appSecret',
                        minWidth: 200,
                        title: 'appSecret',
                        isCheck: false
                    }
                ], // 表头配置
                data: [] // 数据集合
            },
            callback: async (pageInfo: PageInfoInterFace) => {
                return {
                    resultList: dataList,
                    total: 10
                } as ResultInterFace<AppResult>
            },
            authControl: {
                toolbarCustom: true // 展示自定义
            }
        })
        const libDocData: LibDocInterface = {
            title: '自定义表格组件',
            docList: [
                {
                    label: '引入组件',
                    value: "import { IVxeTable } from 'wd-platform-library'"
                },
                {
                    label: '创建表格对象',
                    type: 'pre',
                    value: `
    const tableData = reactive<TableDataInterFace>({
            type: 'app_table', // 每个表格唯一表示符
            tableInfo: {
                columns: [
                    {
                        field: 'appName',
                        minWidth: 150,
                        title: '应用名称',
                        fixed: 'left',
                        isCheck: false
                    },
                    {
                        field: 'appId',
                        minWidth: 150,
                        title: '应用ID'
                    },
                    {
                        field: 'appSecret',
                        minWidth: 200,
                        title: 'appSecret'
                    }
                ], // 表头配置
                data: [] // 数据集合
            },
            callback: async (pageInfo: PageInfoInterFace) => {
                return {
                    resultList: dataList,
                    total: 10
                } as ResultInterFace<AppResult>
            },
            authControl: {
                toolbarCustom: true // 展示自定义
            }
        })
        `
                },
                {
                    label: '关键代码:isCheck',
                    type: 'pre',
                    value: `
    tableInfo: {
                columns: [
                    {
                        field: 'appName',
                        minWidth: 150,
                        title: '应用名称',
                        fixed: 'left',
                        isCheck: false  //true:右上角自定义可选   false:不可选  默认值为true
                    },
                    {
                        field: 'appId',
                        minWidth: 150,
                        title: '应用ID'
                    },
                    {
                        field: 'appSecret',
                        minWidth: 200,
                        title: 'appSecret'
                    }
                ], 
    },`
                }

            ]
        }
        return {
            tableData,
            iVxeTableRef,
            libDocData
        }
    },
    components: {
        IVxeTable,
        LibDoc
    }
})
</script>

<style lang="scss" scoped>
.cus_template {
  display: flex;
}
</style>
